/**
 * ReportGear(2011)
 */
package com.reportgear.designer.gui.component.list;

import java.awt.Component;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;

import javax.swing.DefaultCellEditor;
import javax.swing.JList;
import javax.swing.JTextField;

/**
 * 
 * 
 * @version 1.0 2011-4-25
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class DefaultListCellEditor extends DefaultCellEditor implements ListCellEditor {
	/**
	 * UID
	 */
	private static final long serialVersionUID = 7917681585360887524L;

	/**
	 * @param textField
	 *            文本字段
	 */
	public DefaultListCellEditor(JTextField textField) {
		super(textField);
	}

	public Component getListCellEditorComponent(JList list, Object name, boolean isSelected, int index) {
		this.delegate.setValue(name);

		if (this.editorComponent != null)
			this.editorComponent.addFocusListener(new FocusAdapter() {
				public void focusLost(FocusEvent paramFocusEvent) {
					stopCellEditing();
				}
			});

		return this.editorComponent;
	}
}